home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Found / FWExcLib / Include / FWAutoDe.h next >
Encoding:
C/C++ Source or Header  |  1995-11-08  |  3.5 KB  |  116 lines  |  [TEXT/MPS ]

  1. #ifndef FWAUTODE_H
  2. #define FWAUTODE_H
  3. //========================================================================================
  4. //
  5. //    File:                FWAutoDe.h
  6. //    Release Version:    $ 1.0d11 $
  7. //
  8. //    Copyright:    (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include <stddef.h>
  13.  
  14. #ifndef FWSEXCEP_H
  15. #include "FWSExcep.h"
  16. #endif
  17.  
  18. #ifndef FWEXCDEF_H
  19. #include "FWExcDef.h"
  20. #endif
  21.  
  22. #if FW_LIB_EXPORT_PRAGMAS
  23. #pragma lib_export on
  24. #endif
  25.  
  26. //========================================================================================
  27. //    Forward Declarations
  28. //========================================================================================
  29.  
  30. #ifdef FW_USE_NEW_HELPER    
  31. class FW_CLASS_ATTR FW_CPrivNewHelper;
  32. #endif
  33.  
  34. //========================================================================================
  35. // CLASS _FW_CAutoDestructObject
  36. //
  37. //    Every stack based object that must be destructed when the stack is unwound must have
  38. //    a virtual destructor as the first item in its vtbl.  This root class ensures that 
  39. //    is the case.
  40. //========================================================================================
  41.  
  42. class FW_CLASS_ATTR _FW_CAutoDestructObject
  43. {
  44.  
  45. public:
  46.  
  47.     virtual ~ _FW_CAutoDestructObject();
  48.         // Virtual destructor.  Does nothing other than reserve vtbl slot.
  49.  
  50. #ifdef FW_USE_NEW_HELPER    
  51.     void* operator new(size_t size, void* p);
  52.     void* operator new(size_t size, const FW_CPrivNewHelper &helper);
  53.     void operator delete(void *object);
  54. #endif
  55.  
  56.     // this class needs to allocate memory in its operators new and delete.  But
  57.     // without knowing about higher-level components, how can it do this using
  58.     // the application's heap manager?  Well, you must use the next two methods to
  59.     // set memory management hooks which then will be used to in new and delete
  60.     static void SetOperatorNewHandler(__FW_OperatorNewHandler operatorNewHandler);
  61.     static void SetOperatorDeleteHandler(__FW_OperatorDeleteHandler operatorDeleteHandler);
  62.  
  63.     static __FW_OperatorNewHandler GetOperatorNewHandler();
  64.     static __FW_OperatorDeleteHandler GetOperatorDeleteHandler();
  65.  
  66. #ifndef FW_NATIVE_EXCEPTIONS
  67. public: // Internal Method
  68.  
  69.     void __Delete();
  70.         // Calls virtual destructor.  To be used only by the exception library
  71.         
  72. #endif // FW_NATIVE_EXCEPTIONS
  73.  
  74. private:
  75. #ifdef FW_USE_NEW_HELPER    
  76.     void* operator new(size_t size) { return NULL; };
  77. #endif
  78. };
  79.  
  80. #ifndef FW_NATIVE_EXCEPTIONS
  81.  
  82. #ifndef __BORLANDC__
  83. //========================================================================================
  84. // CLASS _FW_CAutoDestructObject inline functions
  85. //========================================================================================
  86.  
  87. //----------------------------------------------------------------------------------------
  88. // _FW_CAutoDestructObject::__Delete
  89. //----------------------------------------------------------------------------------------
  90. inline void _FW_CAutoDestructObject::__Delete()
  91. {
  92. #ifdef _MPWCFRONT
  93.     // CFront is bizarre.  It won't allow the unscoped destructor name, but the scoped 
  94.     // name is dispatched virtually, even though ARM says scoped names are never virtual.
  95.     this->_FW_CAutoDestructObject::~_FW_CAutoDestructObject();
  96. #else
  97.     this->~_FW_CAutoDestructObject();    // Virtual dispatch to object's destructor
  98. #endif
  99. }
  100. #endif
  101.  
  102. #ifdef FW_USE_NEW_HELPER    
  103. inline void* _FW_CAutoDestructObject::operator new(size_t size, void* p)
  104. {
  105.     return p;
  106. }
  107. #endif
  108.  
  109. #endif // FW_NATIVE_EXCEPTIONS
  110.  
  111. #if FW_LIB_EXPORT_PRAGMAS
  112. #pragma lib_export off
  113. #endif
  114.  
  115. #endif
  116.